package logic

import (
	"context"
	"zhihu-new/zhihurpc/zhihurpcclient"

	"zhihu-new/api/internal/svc"
	"zhihu-new/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PrefaceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPrefaceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PrefaceLogic {
	return &PrefaceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PrefaceLogic) Preface(req *types.PrefaceRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	preface, err := l.svcCtx.ZhiHuRpc.Preface(l.ctx, &zhihurpcclient.PrefaceRequest{
		UserId:   req.UserId,
		Images:   req.Images,
		Nickname: req.Nickname,
		Info:     req.Info,
		Address:  req.Address,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "完善个人信息成功",
		Code:    200,
		Data:    preface,
	}, nil
}
